#!/usr/bin/bash
nasm -f elf32 multiboot.asm -o multiboot.o
if [ $? -ne 0 ];then exit 1;fi
g++ -m32 -std=c++14 -ffreestanding -nostdlib -c kernel.cpp -o kernel.o
if [ $? -ne 0 ];then exit 1;fi
ld -m elf_i386 -T multiboot.ld multiboot.o kernel.o -o kernel.bin
if [ $? -ne 0 ];then exit 1;fi
mkdir -pv grub-debug/boot/grub
cat > grub-debug/boot/grub/grub.cfg <<- "EOF"
menuentry "Genshin" {
    multiboot /boot/mykernel/kernel.bin
    boot
}
EOF
mkdir -pv grub-debug/boot/mykernel
cp kernel.bin grub-debug/boot/mykernel/ -v
grub-mkrescue -o myos.iso grub-debug/
qemu-system-x86_64 --enable-kvm -machine pc -cpu host -m 4096 -cdrom myos.iso